﻿@model Sharp.WebBooter.Areas.CMS.Models.SpecialViewModel
@{
    Layout = null;
}
<style type="text/css">
    .Special_Edit {
    }

        .Special_Edit .form-body {
            margin-bottom: 4px;
        }

        .Special_Edit .VIUList .fa-minus-circle {
            cursor: pointer;
        }

    #viuList .modal-header {
        padding-bottom: 0px;
    }

    #viuList .modal-body {
        padding-top: 0px;
    }
</style>
<section class="content-header">
    <h1>
        <a href="javascript:window.app.loadUI('@Url.Action("Create")')">编辑专题</a>
    </h1>
    <ol class="breadcrumb">
        <li>
            <a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a>
        </li>
        <li class="">专题</li>
        <li class="active">专题管理</li>
    </ol>
</section>
<section class="content Special_Edit">
    <div class="row">
        <div class="col-md-9">
            <div class="box box-primary">
                <div class="box-body form-horizontal">
                    @Html.HiddenFor(x => x.Id)

                    <div class="form-group">
                        <label class="col-md-3 control-label">栏目分类：</label>
                        <div class="col-md-9">
                            <select name="ColmunId" class="form-control">
                                <option value="" selected> 请选择栏目</option>
                                @foreach (var item in Model.Colmuns)
                                {
                                    <option value="@item.Id"> @item.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3">主题：</label>
                        <div class="col-md-9">
                            @Html.Bootstrap().TextBoxFor(x => x.Title)
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3">缩略图：</label>
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-9">
                                    <input id="file-Thumbnail" type="file" class="file-loading" />
                                    <input type="hidden" id="thumbnail" name="thumbnail" value="@Model.Thumbnail" />
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-6 col-md-3" draggable="true">
                                    <div class="thumbnail">
                                        <img id="imgThumbnail" draggable="false" src="@Model.Thumbnail" alt="">
                                        <div class="file-actions">
                                            <div class="file-footer-buttons">
                                                <button class="btn btn-default btn-sm" type="button"> <i class="fa fa-search"></i></button>
                                                <button class="btn btn-danger btn-sm" type="button" id="btnThumbnailDel"> <i class="fa fa-trash"></i></button>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3">VIU关联：</label>
                        <div class="col-md-9">
                            <fieldset style="width: 80%;">
                                <legend>VIU关联 <button class="btn btn-default btn-sm" type="button" onclick="$('#viuList').modal('show');"> <i class="fa fa-plus"></i> </button></legend>
                                <div class="VIUList">
                                    <ul style="max-height: 400px;" class="list-unstyled" data-bind="foreach:VIUList">
                                        <li>
                                            <i class="fa fa-minus-circle" data-bind="click:$root.removeVIU"></i>&nbsp;<i data-bind="text:$index()+1+'、'"></i>
                                            <a data-bind="text:title">手机刷卡乘火车或不再遥远</a>
                                            <input type="hidden" name="viuList" data-bind="value:id" />
                                        </li>
                                    </ul>
                                </div>
                            </fieldset>


                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3">封面图：</label>
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-9">
                                    <input id="file-CoverPictrue" type="file" class="file" />
                                    <input type="hidden" id="coverPictrue" value="@Model.CoverPictrue" name="coverPictrue" />
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-6 col-md-3" draggable="true">
                                    <div class="thumbnail">
                                        <img id="imgCoverPictrue" draggable="false" src="@Model.CoverPictrue" alt="">
                                        <div class="file-actions">
                                            <div class="file-footer-buttons">
                                                <button class="btn btn-default btn-sm" type="button"> <i class="fa fa-search"></i></button>
                                                <button class="btn btn-danger btn-sm" type="button" id="btnCoverPictrueDel"> <i class="fa fa-trash"></i></button>
                                            </div>
                                            <div class="clearfix"></div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3">描述：</label>
                        <div class="col-md-9">
                            @Html.Bootstrap().TextareaFor(x => x.Content)
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3">模板文件：</label>
                        <div class="col-md-9">
                            <input type="text" style="width: 157px;" value="show.html" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="box box-primary">
                <div class="box-body form-horizontal">


                    <div class="form-group">
                        <label class="col-sm-12">阅读数：</label>
                        <div class="col-sm-12">
                            @Html.Bootstrap().TextBoxFor(x => x.Hits).Type().Number()
                        </div>
                    </div>


                </div>
            </div>

        </div>
    </div>
    <div class="box-footer text-center box-outfooter">

        <button class="btn btn-primary" data-bind="click:saveForm"><i class="fa fa-save"></i> 保存</button>

    </div>
</section>
<div class="modal fade " aria-hidden="true" id="viuList">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title">VIU列表</h4>
                <div class="input-group SearchArea">
                    <input type="text" name="title" class="form-control">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default" onclick="window.app.search();"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </div>
            <div class="modal-body">
                <table class="dataTable table table-bordered table-striped table-condensed" id="viuDataList"></table>
            </div>
        </div>
    </div>
</div>
<script src="~/Areas/CMS/ViewModel/Special/Edit.js"></script>
<script type="text/javascript">
    var vm = new Special_Edit_ViewModel();
    vm.init();
    ko.applyBindings(vm, $(".Special_Edit")[0]);

    function selectedThis(id, title) {
        vm.VIUList.unshift({ id: id, title: title });
        $('#viuList').modal('hide');
    }

    var $viuDataList;
    $('#viuList').on('show.bs.modal', function () {
        if ($viuDataList == null) {
            $viuDataList = $('#viuDataList').dataTable({
                displayLength: 10,
                "serverSide": true,
                "ajax": {
                    "url": "@Url.Action("GetPaged", "VIU")",
                    "type": "POST"
                },
                "columnDefs": [
                    { sDefaultContent: '', aTargets: ['_all'] },
                    { "searchable": false, sortable: false, "orderable": false }
                ],
                columns: [
                    { title: "标题", data: 'title', "sClass": "left" },
                    {
                        orderable: false, width: 60, "sClass": "center",
                        "data": function (row) {
                            return "<input class='btn btn-default btn-sm' onclick=\"selectedThis('" + row.id + "','" + row.title + "');\" value='选择' type='button'>";
                        }
                    }
                ]
            });
        }
    });

    var uploaderThumbnail = $("#file-Thumbnail");
    uploaderThumbnail.fileinput({
        uploadUrl: '@Url.Action("ReceivePic","VIU")',
        language: 'zh', //设置语言
        showPreview: false,
        showUpload: true, //是否显示上传按钮
        showCaption: true,//是否显示标题
        uploadAsync: true, showDrag: true,
        allowedFileExtensions: ['jpg', 'png', 'gif'], //接收的文件后缀
        maxFileSize: 4 * 1024,//kb
        uploadExtraData: {
            tempFlag: '@Model.TempFlag'
        }
    })
        .on("filebatchuploadsuccess", function (event, data, previewId, index) {
            //上传成功的一系列操作 ，  比如一些 刷新图片列表
            alert("filebatchuploadsuccess");
        })
        .on("fileuploaded", function (event, data, previewId, index) {
            $('#thumbnail').val(data.response.Data);
            $('#imgThumbnail').attr('src', data.response.Data);
        });


    var uploaderCoverPictrue = $("#file-CoverPictrue");
    uploaderCoverPictrue.fileinput({
        uploadUrl: '@Url.Action("ReceivePic","VIU")',
        language: 'zh', //设置语言
        showPreview: false,
        showUpload: true, //是否显示上传按钮
        showCaption: true,//是否显示标题
        uploadAsync: true, showDrag: true,
        allowedFileExtensions: ['jpg', 'png', 'gif'], //接收的文件后缀
        uploadExtraData: {
            tempFlag: '@Model.TempFlag'
        }
    })
        .on("filebatchuploadsuccess", function (event, data, previewId, index) {
            //上传成功的一系列操作 ，  比如一些 刷新图片列表
            alert("filebatchuploadsuccess");
        })
        .on("fileuploaded", function (event, data, previewId, index) {
            $('#coverPictrue').val(data.response.Data);
            $('#imgCoverPictrue').attr('src', data.response.Data);
        });


    $('#btnThumbnailDel').click(function () {
        swal({
            title: "请确认是否删除？",
            text: "您正在进行删除操作，该操作不可逆!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger"
        }).then(function (isConfirm) {
            if (isConfirm === true) {
                $('#thumbnail').val('');
                $('#imgThumbnail').attr('src', '');
                swal("已经删除", "你已经删除成功！", "success");
            }
        });
    });

    $('#btnCoverPictrueDel').click(function () {
        swal({
            title: "请确认是否删除？",
            text: "您正在进行删除操作，该操作不可逆!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger"
        }).then(function (isConfirm) {
            if (isConfirm === true) {
                $('#coverPictrue').val('');
                $('#imgCoverPictrue').attr('src', '');
                swal("已经删除", "你已经删除成功！", "success");
            }
        });
    });

</script>